package com.qbw.app.module.vehicle.holder;

import android.content.Context;
import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;
import android.view.ViewGroup;

import com.qbw.app.BR;
import com.qbw.app.R;
import com.qbw.app.databinding.VehicleHolderProblemCategoryBinding;
import com.qbw.app.module.common.holder.CommonHolder;

/**
 * @author QBW
 * @date 2019-09-01
 */
public class VehicleProblemCategoryHolder extends CommonHolder<VehicleProblemCategoryHolder.Data, VehicleHolderProblemCategoryBinding> {

    public VehicleProblemCategoryHolder(Context context, ViewGroup viewParent, Object listener) {
        super(context, R.layout.vehicle_holder_problem_category, viewParent, listener);
    }

    @Override
    public void bindData(int position, Data data) {
        super.bindData(position, data);
        mBinding.setData(data);
        mBinding.tvCategory.setText(data.getCategory());
        itemView.setOnClickListener(mClickListenerItem);
    }

    @Override
    protected void onClickItem() {
        super.onClickItem();
        if (mListener instanceof Listener) {
            mData.setOpened(!mData.isOpened());
            ((Listener) mListener).onClickVehicleProblemCategory(mData);
        }
    }

    public interface Listener {
        void onClickVehicleProblemCategory(Data data);
    }

    public static class Data extends BaseObservable {
        private boolean mOpened = true;
        private String mCategory;

        public Data(String category) {
            mCategory = category;
        }

        @Bindable
        public boolean isOpened() {
            return mOpened;
        }

        public void setOpened(boolean opened) {
            mOpened = opened;
            notifyPropertyChanged(BR.opened);
        }

        public String getCategory() {
            return mCategory;
        }
    }
}
